package com.ruoyi.lock.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.lock.domain.AAddress;
import com.ruoyi.lock.service.IAAddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 地址管理Controller
 * 
 * @author ruoyi
 * @date 2024-03-09
 */
@RestController
@RequestMapping("/lock/address")
public class AAddressController extends BaseController
{
    @Autowired
    private IAAddressService aAddressService;

    /**
     * 查询地址管理列表
     */
    @PreAuthorize("@ss.hasPermi('lock:address:list')")
    @GetMapping("/list")
    public TableDataInfo list(AAddress aAddress)
    {
        startPage();
        List<AAddress> list = aAddressService.selectAAddressList(aAddress);
        return getDataTable(list);
    }

    @GetMapping("/selectXY")
    public AjaxResult selectXY()
    {
        List<AAddress> list = aAddressService.selectXY(new AAddress());
        return success(list);
    }

    @GetMapping("/list2")
    public TableDataInfo list2(AAddress aAddress)
    {
        List<AAddress> list = aAddressService.selectAAddressList(aAddress);
        return getDataTable(list);
    }
    /**
     * 导出地址管理列表
     */
    @PreAuthorize("@ss.hasPermi('lock:address:export')")
    @Log(title = "地址管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AAddress aAddress)
    {
        List<AAddress> list = aAddressService.selectAAddressList(aAddress);
        ExcelUtil<AAddress> util = new ExcelUtil<AAddress>(AAddress.class);
        util.exportExcel(response, list, "地址管理数据");
    }

    /**
     * 获取地址管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('lock:address:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(aAddressService.selectAAddressById(id));
    }

    /**
     * 新增地址管理
     */
    @PreAuthorize("@ss.hasPermi('lock:address:add')")
    @Log(title = "地址管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AAddress aAddress)
    {
        return toAjax(aAddressService.insertAAddress(aAddress));
    }

    /**
     * 修改地址管理
     */
    @PreAuthorize("@ss.hasPermi('lock:address:edit')")
    @Log(title = "地址管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AAddress aAddress)
    {
        return toAjax(aAddressService.updateAAddress(aAddress));
    }

    /**
     * 删除地址管理
     */
    @PreAuthorize("@ss.hasPermi('lock:address:remove')")
    @Log(title = "地址管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(aAddressService.deleteAAddressByIds(ids));
    }
}
